<template>
  <div class="chart" ref="lineChart"></div>
</template>

<script lang="ts">
export default {
  name: "LineChart",
};
</script>

<script lang="ts" setup>
import * as echarts from "echarts";
import { watch, ref } from "vue";

const props = defineProps<{
  data: number[];
  axis: string[];
}>();

const lineChart = ref();

watch(
  () => props.data,
  () => {
    const myEcharts = echarts.init(lineChart.value);
    const option = {
      xAxis: {
        data: props.data,
        // 坐标轴留白
        boundaryGap: false,
      },
      yAxis: {
        // 隐藏y轴
        show: false,
      },
      grid: {
        top: 0,
        bottom: 0,
        left: 0,
        right: 0,
      },
      series: {
        type: "line",
        data: props.data,
        // 折线拐点样式
        itemStyle: {
          // 隐藏
          opacity: 0,
        },
        // 是否平滑曲线显示
        smooth: true,
        // 区域填充样式
        areaStyle: {
          // opacity 默认 0.7
          opacity: 1,
          color: "#a64ca6",
        },
        // 线条样式
        lineStyle: {
          color: "#a64ca6",
        },
      },
    };
    // 生成图表
    myEcharts.setOption(option);
  }
);
</script>

<style scoped>
.chart {
  width: 100%;
  height: 100%;
}
</style>
